#include <esp_log.h>
#include <esp_http_server.h>

static httpd_handle_t server = NULL;
#define EXAMPLE_HTTP_QUERY_KEY_MAX_LEN  (64)
static const char *TAG = "web server";


/***************************** */ /*
    依赖符号
*/ /****************************** */
extern httpd_uri_t echo;
extern httpd_uri_t html_default;






httpd_handle_t start_webserver(void)
{
    server = NULL;
    httpd_config_t config = HTTPD_DEFAULT_CONFIG();
    config.lru_purge_enable = true;

    // Start the httpd server
    ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
    if (httpd_start(&server, &config) == ESP_OK) {
        // Set URI handlers
        ESP_LOGI(TAG, "Registering URI handlers");
        httpd_register_uri_handler(server, &html_default);
        httpd_register_uri_handler(server, &echo);
        //
        return server;
    }

    ESP_LOGI(TAG, "Error starting server!");
    return NULL;
}


void stop_webserver(void)
{
    if (server) {
        httpd_stop(server);
    }
}